package com.car.servlet;

import com.car.service.UserService;
import com.car.entyti.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/updateUser")
public class updateUserServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        String id = req.getParameter("id");
        String xm = req.getParameter("name");
        String xb = req.getParameter("sex");
        String dh = req.getParameter("phone");
        String ty = req.getParameter("type");
        String acc = req.getParameter("account");
        String pwd = req.getParameter("password");

        User user = new User();
        user.setId(Integer.parseInt(id));
        user.setName(xm);
        user.setSex(xb);
        user.setPhone(dh);
        user.setType(Boolean.parseBoolean(ty));
        user.setAccount(acc);
        user.setPassword(pwd);

        UserService userService = new UserService();
        userService.updateUser(user);

        resp.sendRedirect(req.getContextPath() + "/User.jsp");
    }
}
